<?php
/***************************************************************
*  Copyright notice
*  (c) 2009, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

//
function ws_alert_auth() {
	$objResponse = new xajaxResponse();
	$msg = _lang(':ws:no_permission');
	$objResponse->addAlert($msg);
	
	return $objResponse;
}

function ws_alert_message($msg) {
	$objResponse = new xajaxResponse();
	$objResponse->addAlert($msg);
	
	return $objResponse;
}

function ws_no_response() {
	$objResponse = new xajaxResponse();
	
	return $objResponse;
}

function ws_script_cb($call, $result = '') {
	$objResponse = new xajaxResponse();
	$objResponse->addScriptCall($call, $result);
	
	return $objResponse;
}

function ws_assign($target, $content, $type = 'innerHTML') {
	$objResponse = new xajaxResponse();
	if( !in_array($type, array('innerHTML', 'value')) ) {
		$type = 'innerHTML';
	}
	$objResponse->addAssign($target, $type, $content);
	
	return $objResponse;
}

function ws_check_auth($type = 'customer') {
	if( $type == 'admin' ) {
		if( $_SESSION['suser']->userid > 0 && $_SESSION['suser']->usertype == 'admin' ) {
			return true;
		}
	} elseif( $type == 'member' ) {
		if( $_SESSION['suser']->userid > 0 && in_array($_SESSION['suser']->usertype, array('customer', 'admin')) ) {
			return true;
		}
	} elseif( $type == 'customer' ) {
		if( $_SESSION['suser']->userid > 0 && in_array($_SESSION['suser']->usertype, array('customer')) ) {
			return true;
		}
	} else {
		if( $_SESSION['suser']->userid == 0 ) {
			return true;
		}
	}
	
	return false;
}
//
?>